import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

import TowDef.generic.Enemy;
import TowDef.generic.Map;
import TowDef.generic.Square;
import TowDer.TowerEnemys.Goblin;
import TowDer.TowerEnemys.Move;
import TowDer.TowerEnemys.MoveWave;


public class WindowTest extends JFrame implements MouseListener{
	
	Map map = new Map();
	ImageIcon viejo;
	
	ArrayList <JLabel> labels;
	ArrayList<Enemy> enemys;
	
	Enemy goblin;
	JLabel gob;
	
	Enemy goblin2;
	JLabel gob2;
	
	Enemy goblin3;
	JLabel gob3;
	
	Enemy goblin4;
	JLabel gob4;
	
	Enemy goblin5;
	JLabel gob5;
	
	Enemy goblin6;
	JLabel gob6;
	
	
	JLabel tow;
	
	JLayeredPane layer ;
	
	public WindowTest(Map map){
		
		labels = new ArrayList<JLabel>();
		enemys = new ArrayList<Enemy>();
		
		this.map = map;

		layer = new JLayeredPane();

		
		this.setSize(500,500);
		
		this.add(layer);
		layer.setBounds(0,0,500,500);
		
		
		layer.setLayout(null);

		int x = 0;
		int y = 0;
		
		for(int i = 0; i<10;i++){
			x = 0;
			y = y + 30;
			for(int j = 0; j<10;j++){
				if(i==5){
					JLabel lab = new JLabel(new ImageIcon(getClass().getResource("/img/way.jpg")));
					layer.add(lab, new Integer(0));
					lab.addMouseListener(this);
					lab.setBounds(x, y, 40, 40);
					x = x + 30;
				}
				else{
					JLabel lab = new JLabel(map.getMapSquare()[i][j].getImage());
					layer.add(lab, new Integer(0));
					lab.addMouseListener(this);
					lab.setBounds(x, y, 40, 40);
					x = x + 30;
				}
		}
		}
		
		
		
		tow = new JLabel(new ImageIcon(getClass().getResource("/img/tower.png")));
		layer.add(tow, new Integer(1));
		
		goblin = new Goblin(map);
		goblin.setPosX(0);
		goblin.setPosY(5);

		gob = new JLabel(goblin.getImg());
		System.out.println(goblin.getImg());
		layer.add(gob, new Integer(1));
		gob.setBounds(18,185,40,40);
		
		goblin2 = new Goblin(map);
		goblin2.setPosX(0);
		goblin2.setPosY(5);

		gob2 = new JLabel(goblin2.getImg());
		System.out.println(goblin2.getImg());
		layer.add(gob2, new Integer(1));
		gob2.setBounds(0,185,40,40);
		
		
		goblin3 = new Goblin(map);
		goblin3.setPosX(0);
		goblin3.setPosY(5);

		gob3 = new JLabel(goblin3.getImg());
		System.out.println(goblin3.getImg());
		layer.add(gob3, new Integer(1));
		gob3.setBounds(35,185,40,40);
		
		
		goblin4 = new Goblin(map);
		goblin4.setPosX(0);
		goblin4.setPosY(5);

		gob4 = new JLabel(goblin4.getImg());
		System.out.println(goblin4.getImg());
		layer.add(gob4, new Integer(1));
		gob3.setBounds(55,185,40,40);
		
		
		goblin5 = new Goblin(map);
		goblin5.setPosX(0);
		goblin5.setPosY(5);

		gob5 = new JLabel(goblin5.getImg());
		System.out.println(goblin5.getImg());
		layer.add(gob5, new Integer(1));
		gob5.setBounds(95,185,40,40);
		
		
		

		Thread hilo= new Move(goblin, gob,map);
		hilo.start();
		
		Thread hilo2= new Move(goblin2, gob2,map);
		hilo2.start();
		
		Thread hilo3= new Move(goblin3, gob3,map);
		hilo3.start();
		
		Thread hilo4= new Move(goblin4, gob4,map);
		hilo4.start();
		
		Thread hilo5= new Move(goblin5, gob5,map);
		hilo5.start();
		
		Thread hilo6= new Move(goblin6, gob6,map);
		hilo6.start();
		
		
		
		this.setVisible(true);

		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	public static void main(String[] args)
	{
		new WindowTest(new Map());
	}
	@Override
	public void mouseClicked(MouseEvent e) {
//		 TODO Auto-generated method stub
		JLabel org = (JLabel) e.getSource();
		tow.setBounds(org.getX(), org.getY(), 40, 40);
	}
	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		JLabel image = (JLabel) e.getSource();
		viejo =  (ImageIcon) image.getIcon();
		image.setIcon(new ImageIcon(getClass().getResource("/img/select.jpg")));
	}
	
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		JLabel image = (JLabel) e.getSource();
		image.setIcon(viejo);
	}
}
